package com.example.light.system;

import com.example.light.system.service.IoTPulsarConsume;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;

@EnableScheduling
@SpringBootApplication
@MapperScan("com.example.light.system.mapper")
public class LightControlSystemRearEndApplication {

    @Autowired
    private IoTPulsarConsume iotPulsarConsume; // 自动注入IoTPulsarConsume而不是主动创建它的实例

    public static void main(String[] args) {
        SpringApplication.run(LightControlSystemRearEndApplication.class, args);
    }

    @PostConstruct
    public void init() {
        // 在另一个线程中运行iotPulsarConsume的start方法
        Thread thread = new Thread(() -> {
            try {
                iotPulsarConsume.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        thread.start(); // 启动线程
    }
}

